package com.longge.wechat.controller.wx;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.longge.wechat.message.post.Article;
import com.longge.wechat.message.post.News;
import com.longge.wechat.message.post.PostArticleMessage;
import com.longge.wechat.message.wxUtil.WeiXinUtil;



@Controller
public class PostArticleController {

	@RequestMapping(value = "/respArticle.do", method = RequestMethod.POST)
	protected void doPost2(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String content = "";
		String openId = (String) request.getAttribute("openId");
		
		PostArticleMessage pam = new PostArticleMessage();
		pam.setTouser(openId);
		pam.setMsgtype("news");
		News news = new News();
		
		List<Article> articles = new ArrayList<Article>();
		Article article1 = new Article();
		article1.setDescription("这是客服发送图文测试");
		article1.setPicurl("11111111111111");
		article1.setTitle("客服发送图文测试");
		article1.setUrl("2222222222");
		
		Article article2 = new Article();
		article2.setDescription("这是客服发送图文测试");
		article2.setPicurl("11111111111111");
		article2.setTitle("客服发送图文测试");
		article2.setUrl("2222222222");
		
		articles.add(article1);
		articles.add(article2);
		news.setArticles(articles);
		pam.setNews(news);
		
		int result = WeiXinUtil.sendInfo(pam);
		if(result == 1) {
			content = "发送图文消息成功";
		}
		System.out.println(content);
	}
}
